<?php
include_once("adminBase.php");
include_once(_INC_PATH.'catecae.php');

class TechCate extends AdminBase
{
	function index(){
		$sql = "select * from tbl_tech_cate where del_flg='0'";
		$this->db->setQuery($sql);
		$rows = $this->db->loadList();
		$this->smarty->assign("rows",$rows);
		adminDisplay("admin_tech_cate.tpl");
	}

	function addcate(){
		$temprow = array();
		$temprow['name'] = trim($_POST['name']);
		$temprow['des'] = htmlspecialchars(trim($_POST['des']));
		$temprow['ord'] = intval($_POST['ord']);
		if(!empty($_FILES['techImg']) && $_FILES['techImg']['error'] == 0)
		{
			$srcFile = $_FILES['techImg'];
			$imgName = time();
			$file_info = pathinfo($srcFile["name"]); 
			$file_ext = $file_info["extension"];
			$destFile = array('width'=>'132','height'=>'99','img_name'=>$imgName,'upload_path'=>_IMG_PATH.'/tech/techcate/');
			uploadImage($srcFile,$destFile);
			$temprow['techImg'] = '/images/tech/techcate/'.$imgName.'.'.$file_ext;
		}
		if(isset($_POST['id']) && $_POST['id'] > 0){
			$id = intval($_POST['id']);
			$where = " where id=$id";
			$this->db->update($temprow, 'tbl_tech_cate', $where);
		}else{
			$this->db->insert($temprow, 'tbl_tech_cate');
		}
		$_SESSION['sysMsg'] = '编辑成功';
		$this->index();
	}

	function delcate(){
		$id = intval($_POST['id']);
		if($id > 0){
			$sql = "update tbl_tech_cate set del_flg='1' where id='$id'";
			$this->db->query($sql);
		}
		$this->index();
	}
}

$techCate = new TechCate();

?>